Memory Manager

Manages main memory (RAM) of the system
Ensures each process gets access to the memory it needs

The Memory Manager:

Memory Addressing

The memory inside a system (RAM) can be viewed as a linear sequence of bytes

Process Memory

A program exists on disk as a binary executable file

Stack and Heap

The stack grows downwards from the top of the process address space
The process instructions (text) start at the bottom of the image
The memory footprint of a process includes two other areas

Process Image:

Compile-Time Address Binding

Loops and jump locations are turned into fixed memory addresses during compilation
With compile-time binding, a program is assumed to always occupy the same area of memory every time it is executed

start:
	mov eax, 2
	mul ebx
	jmp start

The jump location (start label) is turned into a memory address when compiled

Load-Time Address Binding

Loops and jump locations are turned into relative addresses during compilation
With load-time binding, a program can be loaded anywhere in memory
For the same code, the jump location is encoded as a relative address when compiled

Dynamic (Run-Time) Address Binding

Loops and jump locations are turned into relative addresses during compilation
All processes have their own address space that starts at location zero

Simple Memory Management

Processes are loaded into contiguous memory locations
Each process has a base or datum (where it starts) and a limit (its length)

Choosing Free Space

When a process terminates, its memory space is deallocated and becomes free again
Memory manager needs to decide where to load new processes

Memory Allocation Issues

The memory space will become fragmented with small unallocated gaps

Swapping

The system can execute more processes than will fit in physical memory

Linking

Programs make use of third-party library routines
The code for these routines is stored in library images

Dynamic Loading

An alternative to dynamic linking is dynamic loading

Segmentation

Segmentation allows individual parts of a process to occupy different memory locations

An example segment table:

Seg Limit Datum
0 1200 7800
1 1100 11000
2 3700 3100
3 1100 1400
4 1200 9000
For example, segment 0 of this process starts at memory location 7800 and has a length of 1200
For example,
Advantages

Memory allocation reflects the high-level program structure

Segment Sharing

Suppose two processes run the same program with different data

Intel Segment Registers

The Intel CPU includes six registers that point to segments used by the current process

Segmentation has fallen out of use in modern operating systems